import 'package:flutter/material.dart';
import 'package:cached_network_image/cached_network_image.dart';

/// 图虫页面图片全屏
class WormImagePage extends StatelessWidget {
  final String tag;

  /// 图片地址
  final String url;

  /// 构造方法
  WormImagePage({Key key, this.tag, this.url}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
        theme: ThemeData(primaryColor: Colors.red),
        home: Scaffold(
            body: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          crossAxisAlignment: CrossAxisAlignment.center,
          children: <Widget>[
            Container(
              color: Colors.white,
              child: InkWell(
                onTap: () => Navigator.of(context).pop(), // 关闭当前页面
                child: Hero(
                  tag: this.tag, // 使 TAG 唯一
                  child: CachedNetworkImage(
                      errorWidget: (context, url, error) => Icon(Icons.error),
                      placeholder: (context, url) =>
                          CircularProgressIndicator(),
                      imageUrl: this.url), // 图片缓存
                ),
              ),
            ),
          ],
        )));
  }
}
